package com.yfg.wap.flight.web;

import java.util.List;
import java.util.TreeMap;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.yfg.wap.flight.common.Tools;
import com.yfg.wap.flight.dao.OrderService;
import com.yfg.wap.flight.entity.PlanItinerary;
import com.yfg.wap.flight.entity.base.CheckFlightItem;
import com.yfg.wap.flight.entity.base.ContactInfo;
import com.yfg.wap.flight.entity.base.OrderInfo;
import com.yfg.wap.flight.entity.base.Passenger;
import com.yfg.wap.flight.entity.base.SearchPojo;

public class OrderCreateAction {
	
	public String create(){
		OrderService os = new OrderService();
		OrderInfo info = new OrderInfo();
		TreeMap tm = (TreeMap)ServletActionContext.getRequest().getSession().getAttribute("tm");
		HttpServletRequest request = ServletActionContext.getRequest();
		if(Tools.isNotNullOrEmpty(request.getSession().getAttribute("order"))){
			info = (OrderInfo)request.getSession().getAttribute("order");
		}else{
			if(Tools.isNotNullOrEmpty(tm)){
				SearchPojo searchPojo = (SearchPojo)tm.get("searchPojo");
				CheckFlightItem firstItem = null;
				if(searchPojo.getVoyagetype()==2){
					firstItem = (CheckFlightItem)tm.get("firstItem");
					info.setFirstItem(firstItem);
				}
				CheckFlightItem chooseLine = (CheckFlightItem)tm.get("choseLine");
				info.setChooseLine(chooseLine);
				info.setContactInfo((ContactInfo)tm.get("contact"));
				if(Tools.isNotNullOrEmpty(tm.get("travel"))){
					info.setItinerary((PlanItinerary)tm.get("travel"));
				}
				info.setPassengeres((List<Passenger>) tm.get("passenger"));
				info.setVoyagetype(searchPojo.getVoyagetype());
				info.getContactInfo().setMemberNo(request.getSession().getAttribute("memberNo").toString());
				info = os.createOrder(info);
			}
		}
		ServletActionContext.getRequest().getSession().setAttribute("order", info);
		return "order";
	}
}
